package com.koron.css2.baseConfig.impl;

import com.koron.common.bean.query.BaseQueryBean;
import com.koron.css2.baseConfig.bean.ProcessRecordBean;
import com.koron.css2.baseConfig.mapper.ProcessTimeMapper;
import com.koron.css2.common.dto.AttachmentDto;
import com.koron.css2.common.service.AbstractExportExcel;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.css2.serviceManage.utils.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;

import java.util.List;


public class WaterProcessOverDueRecordExport extends AbstractExportExcel {

	@Override
	public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		BaseQueryBean bean = JsonUtils.objectToPojo(req.getData(), BaseQueryBean.class);
		ProcessTimeMapper mapper = factory.getMapper(ProcessTimeMapper.class);
		List<ProcessRecordBean> list = mapper.selectRecordList(bean);	
		for(ProcessRecordBean record: list ) {
			if(record.getProcessState() == null || !"END".equals(record.getProcessState())) {
				record.setProcessState("未结束");
			}else {
				record.setProcessState("已结束");
			}
		}
		// 返回结果 FnInvoiceExport
		AttachmentDto attachment = new AttachmentDto();
		attachment.setBtlTemplate("WaterProcessOverDueRecordExport.btl");
		attachment.setFileTemplate("WaterProcessOverDueRecordExport.xlsx");
		attachment.setData(list);
		attachment.setFileType("excel");
		attachment.setFilename("流程超时记录报表" + CommonUtils.getCurrentDate());
		return attachment;
	}

}
